package org.shagin.jfin.date.cond;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.shagin.jfin.date.DateUtils;

/**
 * The Class ExactDate.
 */
@SuppressWarnings("serial")
public class ExactDate extends DateCondition {

    private static SimpleDateFormat fmt = DateUtils.getSimpleDateFormat();

    private Date dateValue = null;

    /**
     * Instantiates a new exact date.
     * 
     * @param date the date
     */
    public ExactDate(String date) {
        try {
            dateValue = fmt.parse(date);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Instantiates a new exact date.
     */
    public ExactDate() {
        this(DateUtils.format(new Date()));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean validDate(Date date) {
        return super.validDate(date)
                && ((fmt.format(date).equals(fmt.format(dateValue))));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "В день " + DateUtils.format(dateValue) + " " + toString(range);
    }

    /**
     * Gets the date.
     *
     * @return the date
     */
    public Date getDate() {
        return dateValue;
    }

    /**
     * Sets the date.
     *
     * @param dateValue the new date
     */
    public void setDate(Date dateValue) {
        this.dateValue = dateValue;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String format() {
        return "ExactDate(" + DateUtils.format(dateValue) + ")";
    }
}
